<?php
	session_start();
	
	if(@$_GET['logout']==1){
		$_SESSION['user_admin'] = NULL;
		header('location:index.php');
	}
	if(!@$_SESSION['user_admin']){
		header('location:led-login.php');
	}
	
	include 'db.php';
	//include 'adminControls.php';
	include 'inc/header.php';
	include 'inc/admin.inc.php';
	/*
	if(!isset($_SESSION['user'])){
		header("location:led-admin.php");
	}
	*/
?>

<!DOCTYPE HTML>
<html>
    <head>
    <meta charset=utf-8>
    <title>LEDLAMPS</title>
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
    <script src="js/modernizr-1.7.min.js"></script><!-- this is the javascript allowing html5 to run in older browsers -->
    
    
    <link rel="stylesheet" type="text/css" href="css/reset.css" media="screen" title="html5doctor.com Reset Stylesheet" />
    
    <link rel="stylesheet" href="css/default.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" media="screen" />
    
    <!-- in the CSS3 stylesheet you will find examples of some great new features CSS has to offer -->
    <link rel="stylesheet" type="text/css" href="css/css3.css" media="screen" />
    
    <!-- general stylesheet contains some default styles, you do not need this, but it helps you keep a uniform style -->
    <link rel="stylesheet" type="text/css" href="css/general.css" media="screen" />
    
    <!-- grid's will help you keep your website appealing to your users, view 52framework.com website for documentation -->
    <link rel="stylesheet" type="text/css" href="css/grid.css" media="screen" />
    </head>
<body  class="body-admin">
	<?php get_header('admin'); ?>
    <!-- start admin-tabs -->
    <div id="admin-tabs">
    	<!-- start inner-admin-tabs -->
    	<div class="col_16 centerbox">
    	<ul>
        	<li class="<?php if(!@$_GET['mngr']){ tabIsActive('prod', 'prod'); }else{ tabIsActive(@$_GET['mngr'], 'prod');} ?>">
            	<a href="?mngr=prod&subpg=update"><span>Manage Products</span></a>
            </li>
            <li class="<?php tabIsActive(@$_GET['mngr'], 'cat'); ?>">
            	<a href="?mngr=cat&subpg=view"><span>Categories</span></a>
            </li>
            <li class="<?php tabIsActive(@$_GET['mngr'], 'feat'); ?>">
            	<a href="?mngr=feat&subpg=view"><span>Features</span></a>
            </li>
            <li class="<?php tabIsActive(@$_GET['mngr'], 'cust'); ?>">
            	<a href="?mngr=cust&subpg=view"><span>Manage Customers</span></a>
            </li>
            <li class="<?php tabIsActive(@$_GET['mngr'], 'inv'); ?>">
            	<a href="?mngr=inv&subpg=view"><span>Manage Invoices</span></a>
            </li>
            <li class="<?php tabIsActive(@$_GET['mngr'], 'sale'); ?>">
            	<a href="?mngr=sale&subpg=add"><span>Manage Salesmen</span></a>
            </li>
        </ul>
        <div class="clear"></div>
        </div>
        <!-- end inner-admin-tabs -->
    </div>
	<!-- end admin-tabs -->
    <!-- start adminHeading -->
    <div id="products-head" class="adminHeading">
    	<!-- start headingWrap -->
    	<div class="col_16 centerbox headingWrap">
        	<div class="col_7 left adminHLeft">
        	Hello, <strong>Admin</strong>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<a href="?logout=1"><i class="icon-off"></i> LOGOUT</a>
            </div>
            <div class="col_7 right adminHRight">
            <?php 
		
					if(@$_GET['mngr'] == 'prod'){ ?>
					<ul class="subtabs adminheading-product productTabs">
						<li><a href="?mngr=prod&subpg=add"><i class="icon-plus-sign"></i> ADD </a></li>
						<!--<li><a href="?mngr=prod&subpg=update"><i class="icon-refresh"></i> UPDATE  </a></li>-->
						<li><a href="?mngr=prod&subpg=delete"><i class="icon-trash"></i>  TRASH </a></li>
					</ul>
             	<?php } if(@$_GET['mngr'] == 'cat'){ ?>
					<ul class="subtabs adminheading-product productTabs">
						<li><a href="?mngr=cat&subpg=add"><i class="icon-plus-sign"></i> ADD CATEGORY</a></li>
					</ul>
             	<?php }else if(@$_GET['mngr'] == 'cust'){ ?>
                	<ul class="subtabs adminheading-customer customerTabs">
                    	
						<!--<li><a href="?mngr=cust&subpg=view"><i class="icon-eye-open"></i> VIEW </a></li>-->
                        <li><a href="?mngr=cust&subpg=add"><i class="icon-plus-sign"></i> ADD </a></li>
						<!--<li><a href="?mngr=cust&subpg=edit"><i class="icon-refresh"></i> UPDATE  </a></li>-->
						<li><a href="?mngr=cust&subpg=delete"><i class="icon-trash"></i>  TRASH </a></li>
					</ul>
                 <?php } else if(@$_GET['mngr'] == 'inv'){ ?>
                	<ul class="subtabs adminheading-invoice invoiceTabs">
						<li><a href="?mngr=inv&subpg=view"><i class="icon-eye-open"></i> VIEW </a></li>
						<li><a href="?mngr=inv&subpg=filtersalesman&filter=salesman"><i class="icon-user"></i> FILTER BY SALESMAN  </a></li>
						<li><a href="?mngr=inv&subpg=filterdate&filter=date"><i class="icon-calendar"></i>  FILTER BY DATE </a></li>
					</ul>
                 <?php }  else if(@$_GET['mngr'] == 'sale'){ ?>
                	<ul class="subtabs adminheading-invoice saleTabs">
						<li><a href="?mngr=sale&subpg=add"><i class="icon-eye-open"></i> ADD </a></li>
						<li><a href="?mngr=sale&subpg=edit"><i class="icon-user"></i> EDIT  </a></li>
						<li><a href="?mngr=sale&subpg=delete"><i class="icon-calendar"></i>  DELETE </a></li>
					</ul>
                 <?php } else if(!@$_GET['mngr']){
				 
				 ?>
                 	<ul class="subtabs adminheading-product productTabs">
						<li><a href="?mngr=prod&subpg=add"><i class="icon-plus-sign"></i> ADD </a></li>
					
						<li><a href="?mngr=prod&subpg=delete"><i class="icon-trash"></i>  DELETE </a></li>
					</ul>
                 <?php
				 }else if(@$_GET['mngr']=='feat'){
				?>
                	<ul class="subtabs adminheading-product productTabs">
						<li><a href="?mngr=feat&subpg=add"><i class="icon-plus-sign"></i> ADD FEATURES</a></li>
					</ul>
                <?php	 
				 }
				 ?>               
            </div>
            <div class="clear"></div>
			
            
        </div>
        <!-- end headingWrap -->        
    </div>
    <!-- end adminHeading --> 
    <!-- start admin-content -->
    
     <div class="admin-content tab-content" id="<?php
	 	if(isset($_GET['mngr'])){
			$tabVal = $_GET['mngr'];
			switch($tabVal){
				case 'prod':
					echo 'productTabs';
					break;
				case 'cust':
					echo 'customerTabs';
					break;
				case 'cat':
					echo 'categoryTabs';
					break;
				case 'feat':
					echo 'featuresTabs';
					break;
				case 'inv':
					echo 'invoiceTabs';
					break;
				case 'sale':
					echo 'salesTabs';
					break;
				default: 
					echo 'productTabs';
				break; 
			}
		}else{
			echo 'productTabs';
		}
	  ?>-content">
     		<!-- start product-add -->
            <?php 
				if(isset($_GET['action'])){
					$action = $_GET['action'];
					if($action == 'error'){
					echo '<div class="alert loginerror col_9 box-align-center box_shadow"><button type="button" class="close" data-dismiss="alert">×</button><strong>An Error Occured! </strong>Please contact the administrator.</div>';
					}else if($action == 'success'){
					echo '<div class="alert alert-success loginerror col_9 box-align-center box_shadow"><button type="button" class="close" data-dismiss="alert">×</button><strong>Product Add Successful! </strong>The product has added to the database.</div>';
					}else if($action == 'delsuccess'){
						echo '<div class="alert alert-success loginerror col_9 box-align-center box_shadow"><button type="button" class="close" data-dismiss="alert">×</button><strong>Product Delete Successful! </strong>The product has been deactivated. </div>';
					}else if($action == 'ressuccess'){
						echo '<div class="alert alert-success loginerror col_9 box-align-center box_shadow"><button type="button" class="close" data-dismiss="alert">×</button><strong>Product Restore Successful! </strong>The product has been restored. </div>';
					}else if($action == 'custeditsuccess'){
						echo '<div class="alert alert-success loginerror col_9 box-align-center box_shadow"><button type="button" class="close" data-dismiss="alert">×</button><strong>Customer Update Successful! </strong>The customer information has been updated successfully. </div>';
					}else if($action == 'custdelsuccess'){
						echo '<div class="alert alert-success loginerror col_9 box-align-center box_shadow"><button type="button" class="close" data-dismiss="alert">×</button><strong>Customer Deleted! </strong>The customer information has been deleted successfully. </div>';
					}else if($action == 'custressuccess'){
						echo '<div class="alert alert-success loginerror col_9 box-align-center box_shadow"><button type="button" class="close" data-dismiss="alert">×</button><strong>Customer Restored! </strong>The customer information has been restored successfully. </div>';
					}else if($action == 'saleaddsuccess'){
						echo '<div class="alert alert-success loginerror col_9 box-align-center box_shadow"><button type="button" class="close" data-dismiss="alert">×</button><strong>Salesman Added! </strong>The salesman information has been added successfully. </div>';
					}else if($action == 'custaddsuccess'){
						echo '<div class="alert alert-success loginerror col_9 box-align-center box_shadow"><button type="button" class="close" data-dismiss="alert">×</button><strong>Customer Added! </strong>The Customer information has been added successfully. </div>';
					}
				}
            ?>
  
             <?php
			 	if(@$_GET['mngr'] == 'prod' && isset($_GET['subpg'])){
					$subpage = $_GET['subpg'];
					switch($subpage){
						case 'add':
							showProductAdd();
							break;
						case 'update':
							showProductUpdate();
							break;
						case 'update2':
							showProductUpdate_data(@$_GET['id']);
							break;
						case 'delete':
							showProductDelete();
							break;						 
						default: showProductDelete();
					}//end switch
				}else if(@$_GET['mngr'] == 'cust' && isset($_GET['subpg'])){
					$subpage = $_GET['subpg'];
					switch($subpage){
						case 'add':
							showCustomersAdd();;
						break;
						case 'view':
							showCustomersEdit();
							break;
						case 'edit':
							EditCustomerData();
							break;
						case 'delete':
							showCustomerDelete();
							break;
						default: showCustomers();
					}
				}else if(@$_GET['mngr'] == 'inv' && isset($_GET['subpg'])){
					$subpage = $_GET['subpg'];
					switch($subpage){
						case 'view':
							showInvoice();
							break;
						case 'filtersalesman':
							filterSalesman();
							break;
						case 'filterdate':
							filterDate();
							break;
						case 'invoicedetail':
							InvoiceDetails();
							break;
						default: showInvoice();
					}
				}else if(@$_GET['mngr'] == 'sale' && isset($_GET['subpg'])){
					$subpage = $_GET['subpg'];
					switch($subpage){
						case 'add':
							salesmanAdd();
							break;
						case 'edit':
							salesmanEdit();
							break;
						case 'delete':
							salesmanDelete();
							break;
						default: salesmanAdd();
					}
				}else if(@$_GET['mngr'] == 'cat' && isset($_GET['subpg'])){
					$subpage = $_GET['subpg'];
					switch($subpage){
						case 'add':
							CatAdd();
							break;
						default:
							CatView();
						break;
					}
				}else if(@$_GET['mngr'] == 'feat' && isset($_GET['subpg'])){
					$subpage = $_GET['subpg'];
					switch($subpage){
						case 'add':
							featadd();
						break;
						case 'update':
							featadd();
						break;
						default:
							featview();
						break;
					}
				}else{
					showProductUpdate();
				}
			 ?>	 
         </div>
    <!-- end admin-content -->
    <footer class="row">
		<div class="col_16 col">all rights reserved &copy; <a href="#">LEDLAMPS</a> | </div>
	</footer>
    
    
	<?php
		//generateModals();
	?>
    
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript">
		//for filters
		 $(document).ready(function() {
		<?php if (isset($_GET['filter'])){ if($_GET['filter'] == 'salesman'){ ?>		  
			
      			$("#filtersend").click(function(event){		
					//var search_val = $("select#selectsalesm option:selected").val();
					event.preventDefault();
					var datastr = $('#selectsalesm').val();
					//alert(datastr);		
					//$.get("inc/invoice/returnsalesm.inc.php", {searchval: "all"}, function(data){ alert("data loaded : "+data);} );
					
					$.ajax({
					type: "POST",
					url: "inc/invoice/returnsalesm.inc.php",
					data: {searchval: datastr},
					success: function(data){ $('#filtercontent').html(data); /*alert(data);*/ }						
					}); 
					
					//displayResult();  
					    			
      			});
   			
		<?php } else if ($_GET['filter'] == 'date'){ ?>
				$( "#pickdate" ).datepicker({dateFormat: 'MM d, yy' });
				$("#filtersend").click(function(event){		
					//var search_val = $("select#selectsalesm option:selected").val();
					event.preventDefault();
					var datastr = $('#pickdate').val();
					//alert(datastr);
					$.ajax({
						 type: "POST",
						 url: "inc/invoice/returndate.inc.php",
						 data: {searchval: datastr},
						 success: function(data){ $('#filtercontent').html(data); /*alert(data);*/ }
					});
				});
		<?php } } ?>
		
		//for tooltip hovers
		$('.updateLink').tooltip({placement: 'right'});
		$('.edit-customer').tooltip();
		$('.edit-salesman').tooltip();
		$('.view-invoice').tooltip();		
		});
    </script>
</body>
</html>